package com.imgo.max.temporary.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.imgo.max.common.dto.ResultCodeEnum;
import com.imgo.max.common.dto.ResultDO;
import com.imgo.max.common.util.page.PageVO;
import com.imgo.max.common.util.page.Pagination;
import com.imgo.max.core.tools.Collections3;
import com.imgo.max.core.tools.StringUtils;
import com.imgo.max.temporary.dao.SuperGirlConcertActivityMapper;
import com.imgo.max.temporary.dto.SuperGirlConcertActivityDto;

@Service("superGirlConcertActivityManageService")
public class SuperGirlConcertActivityManageServiceImpl implements SuperGirlConcertActivityManageService {
	private static final Logger log = LoggerFactory
			.getLogger(SuperGirlConcertActivityManageServiceImpl.class);

	@Resource
	private SuperGirlConcertActivityMapper superGirlConcertActivityMapper;


	
	/**
	 * 后台使用 SuperGirlConcertActivity
	 */
	 @Override
	public ResultDO<PageVO<SuperGirlConcertActivityDto>> querySuperGirlConcertActivityPage(Pagination pagination, SuperGirlConcertActivityDto superGirlConcertActivityDto) {

		ResultDO<PageVO<SuperGirlConcertActivityDto>> resultDoList = new ResultDO<PageVO<SuperGirlConcertActivityDto>>();
		PageVO<SuperGirlConcertActivityDto> pageVO = new PageVO<SuperGirlConcertActivityDto>();
		List<SuperGirlConcertActivityDto> superGirlConcertActivityDtoList = new ArrayList<SuperGirlConcertActivityDto>();
		try {
			if (pagination != null) {
				int total = superGirlConcertActivityMapper.querySuperGirlConcertActivityCount(superGirlConcertActivityDto);
				pagination.setTotal(total);
			}
			superGirlConcertActivityDtoList = superGirlConcertActivityMapper.querySuperGirlConcertActivityPage(pagination,superGirlConcertActivityDto);
			if (superGirlConcertActivityDtoList != null && superGirlConcertActivityDtoList.size() > 0) {
				pageVO.setList(superGirlConcertActivityDtoList);
				pageVO.setPagination(pagination);
				resultDoList.setModule(pageVO);
				resultDoList.setSuccess(true);
				resultDoList.setResultCode(ResultCodeEnum.SUCCESS.getResultCode());
				return resultDoList;
			}
			pageVO.setList(superGirlConcertActivityDtoList);
			pageVO.setPagination(pagination);
			resultDoList.setModule(pageVO);
			resultDoList.setSuccess(true);
			resultDoList.setResultCode(ResultCodeEnum.COMMON_NO_DATA.getResultCode());
			resultDoList.setErrorMessage(ResultCodeEnum.COMMON_NO_DATA.getMessage());
			return resultDoList;
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			// 返回结果
			pageVO.setList(superGirlConcertActivityDtoList);
			pageVO.setPagination(pagination);
			resultDoList.setSuccess(false);
			resultDoList.setResultCode(ResultCodeEnum.COMMON_FAIL.getResultCode());
			resultDoList.setErrorMessage(e.getMessage());
			return resultDoList;
		}
	}
	 
	 
	/**
	 * 后台使用 SuperGirlConcertActivity and ArtistId
	 */
	 @Override
	public ResultDO<PageVO<SuperGirlConcertActivityDto>> querySuperGirlConcertActivityAndArtistIdPage(Pagination pagination, SuperGirlConcertActivityDto superGirlConcertActivityDto) {

		ResultDO<PageVO<SuperGirlConcertActivityDto>> resultDoList = new ResultDO<PageVO<SuperGirlConcertActivityDto>>();
		PageVO<SuperGirlConcertActivityDto> pageVO = new PageVO<SuperGirlConcertActivityDto>();
		List<SuperGirlConcertActivityDto> superGirlConcertActivityDtoList = new ArrayList<SuperGirlConcertActivityDto>();
		try {
			if (pagination != null) {
				int total = superGirlConcertActivityMapper.querySuperGirlConcertActivityAndArtistIdCount(superGirlConcertActivityDto);
				pagination.setTotal(total);
			}
			superGirlConcertActivityDtoList = superGirlConcertActivityMapper.querySuperGirlConcertActivityAndArtistIdPage(pagination,superGirlConcertActivityDto);
			if (superGirlConcertActivityDtoList != null && superGirlConcertActivityDtoList.size() > 0) {
				pageVO.setList(superGirlConcertActivityDtoList);
				pageVO.setPagination(pagination);
				resultDoList.setModule(pageVO);
				resultDoList.setSuccess(true);
				resultDoList.setResultCode(ResultCodeEnum.SUCCESS.getResultCode());
				return resultDoList;
			}
			pageVO.setList(superGirlConcertActivityDtoList);
			pageVO.setPagination(pagination);
			resultDoList.setModule(pageVO);
			resultDoList.setSuccess(true);
			resultDoList.setResultCode(ResultCodeEnum.COMMON_NO_DATA.getResultCode());
			resultDoList.setErrorMessage(ResultCodeEnum.COMMON_NO_DATA.getMessage());
			return resultDoList;
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			// 返回结果
			pageVO.setList(superGirlConcertActivityDtoList);
			pageVO.setPagination(pagination);
			resultDoList.setSuccess(false);
			resultDoList.setResultCode(ResultCodeEnum.COMMON_FAIL.getResultCode());
			resultDoList.setErrorMessage(e.getMessage());
			return resultDoList;
		}
	}
	 
	 
	/**
	 * 后台使用 添加 SuperGirlConcertActivity
	 * 
	 * @param SuperGirlConcertActivityDto
	 * @return
	 */
	@Transactional
	@Override
	public ResultDO addSuperGirlConcertActivity(SuperGirlConcertActivityDto superGirlConcertActivityDto) {
		ResultDO resultDO = new ResultDO();
		try {
			
			Integer num;
			num = superGirlConcertActivityMapper.addSuperGirlConcertActivity(superGirlConcertActivityDto);
			resultDO.setResultCode(ResultCodeEnum.SUCCESS.getResultCode());
			resultDO.setSuccess(true);
			return resultDO;
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			// 返回结果
			resultDO.setSuccess(false);
			resultDO.setResultCode(ResultCodeEnum.COMMON_FAIL.getResultCode());
			resultDO.setErrorMessage(e.getMessage());
			return resultDO;
		}

	}

	

	/**
	 * 后台使用  查询 SuperGirlConcertActivity by ID
	 * @param Long  id
	 * @return ResultDO
	 */
	@Override
	public ResultDO<SuperGirlConcertActivityDto> querySuperGirlConcertActivityById(Integer id) {
		ResultDO<SuperGirlConcertActivityDto> result = new ResultDO<SuperGirlConcertActivityDto>();
		SuperGirlConcertActivityDto dto = new SuperGirlConcertActivityDto();
		try {
			dto = superGirlConcertActivityMapper.querySuperGirlConcertActivityById(id);
			result.setModule(dto);
			result.setSuccess(true);
			result.setResultCode(ResultCodeEnum.SUCCESS.getResultCode());
			return result;
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			result.setSuccess(false);
			result.setResultCode(ResultCodeEnum.COMMON_FAIL.getResultCode());
			result.setErrorMessage(e.getMessage());
			return result;
		}

	}
	
	/**
	 * 后台使用 修改SuperGirlConcertActivity by ID
	 */
	@Transactional
	@Override
	public ResultDO<Integer> updateSuperGirlConcertActivityById(SuperGirlConcertActivityDto dto) {
		ResultDO<Integer> resultDO = new ResultDO<Integer>();
		Integer num;
		try {
			num = superGirlConcertActivityMapper.updateSuperGirlConcertActivityById(dto);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			// 返回结果
			resultDO.setSuccess(false);
			resultDO.setResultCode(ResultCodeEnum.COMMON_FAIL.getResultCode());
			resultDO.setErrorMessage(e.getMessage());
			return resultDO;
		}
		resultDO.setModule(num);
		resultDO.setResultCode(ResultCodeEnum.SUCCESS.getResultCode());
		resultDO.setSuccess(true);
		return resultDO;
	}
	
	/**
	 * 后台使用 删除  super_girl_concert_artist 
	 */
	@Transactional
	@Override
	public ResultDO<Integer> deleteSuperGirlConcertArtist(SuperGirlConcertActivityDto dto) {
		ResultDO<Integer> resultDO = new ResultDO<Integer>();
		Integer num;
		try {
			num = superGirlConcertActivityMapper.deleteSuperGirlConcertArtist(dto);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			// 返回结果
			resultDO.setSuccess(false);
			resultDO.setResultCode(ResultCodeEnum.COMMON_FAIL.getResultCode());
			resultDO.setErrorMessage(e.getMessage());
			return resultDO;
		}
		resultDO.setModule(num);
		resultDO.setResultCode(ResultCodeEnum.SUCCESS.getResultCode());
		resultDO.setSuccess(true);
		return resultDO;
	}
	
	
	/**
	 * 活动添加艺人
	 */
	@Transactional
	@Override
	public ResultDO insertArtists( List<String> uids,
			String activityid) {
		ResultDO resultDO = new ResultDO();
		if (StringUtils.isBlank(activityid) || Collections3.isEmpty(uids)) {
			resultDO.setResultCode(ResultCodeEnum.MISSING_PARAMS
					.getResultCode());
			resultDO.setSuccess(false);
			return resultDO;
		}
		try {
//			Date createTime = new Date();
			for (String artistId : uids) {
				SuperGirlConcertActivityDto dto = new SuperGirlConcertActivityDto();
				dto.setActivityId(activityid);
				dto.setArtistId(artistId);
				superGirlConcertActivityMapper.insertArtists(dto);
			}
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			resultDO.setResultCode(ResultCodeEnum.ARTIST_ACTIVITY_ERROR
					.getResultCode());
			resultDO.setSuccess(false);
			resultDO = new ResultDO<>(ResultCodeEnum.ARTIST_ACTIVITY_ERROR,
					false);
		}
		return resultDO;
	}
}
